home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / 3d_hyper / 3d_hyper.dcr / Scripts_51_generateMesh Script.ls < prev    next >
Encoding:
Text File  |  2011-06-09  |  29.2 KB  |  599 lines

  1. global gWorld, gSolidFormat, gTransFormat, gTargetPoints, gPowerupList
  2.  
  3. on newGenerateMesh whichTrack
  4.   theTrack = getTrack(whichTrack)
  5.   NumSegs = theTrack.road.count
  6.   DistPerSection = 500.0
  7.   FacesPerSeg = 16
  8.   VerticesPerSeg = 8
  9.   havokFacesPerSeg = 6
  10.   havokVerticesPerSeg = 4
  11.   the randomSeed = 1001
  12.   theTex = gWorld.newTexture("RoadTexture", #fromCastMember, member("Track", "Graphics"))
  13.   roadShader = gWorld.newShader("RoadShader", #standard)
  14.   roadShader.texture = theTex
  15.   roadShader.ambient = rgb(200, 200, 200)
  16.   roadShader.diffuse = rgb(255, 255, 255)
  17.   roadShader.specular = rgb(0, 0, 0)
  18.   roadShader.shininess = 0
  19.   roadShader.useDiffuseWithTexture = 0
  20.   roadShader.textureTransformList[1].scale = vector(1, 1, 1)
  21.   theTex = gWorld.newTexture("RoadTexture2", #fromCastMember, member("Track2", "Graphics"))
  22.   roadShader2 = gWorld.newShader("RoadShader2", #standard)
  23.   roadShader2.texture = theTex
  24.   roadShader2.ambient = rgb(200, 200, 200)
  25.   roadShader2.diffuse = rgb(255, 255, 255)
  26.   roadShader2.specular = rgb(0, 0, 0)
  27.   roadShader2.shininess = 0
  28.   roadShader2.useDiffuseWithTexture = 0
  29.   roadShader2.textureTransformList[1].scale = vector(1, 1, 1)
  30.   roadShaders = [roadShader, roadShader2]
  31.   theTex = gWorld.newTexture("RoadBottomTexture", #fromCastMember, member("trackbottom", "Graphics"))
  32.   roadBotShader = gWorld.newShader("RoadBotShader", #standard)
  33.   roadBotShader.texture = theTex
  34.   roadBotShader.ambient = rgb(200, 200, 200)
  35.   roadBotShader.diffuse = rgb(255, 255, 255)
  36.   roadBotShader.specular = rgb(0, 0, 0)
  37.   roadBotShader.shininess = 0
  38.   roadBotShader.useDiffuseWithTexture = 0
  39.   roadBotShader.textureTransformList[1].scale = vector(1, 0.5, 1)
  40.   theTex = gWorld.newTexture("WallSideTexture", #fromCastMember, member("trackside", "Graphics"))
  41.   wallSideShader = gWorld.newShader("WallSideTexture", #standard)
  42.   wallSideShader.texture = theTex
  43.   wallSideShader.ambient = rgb(200, 200, 200)
  44.   wallSideShader.diffuse = rgb(255, 255, 255)
  45.   wallSideShader.specular = rgb(0, 0, 0)
  46.   wallSideShader.shininess = 0
  47.   wallSideShader.useDiffuseWithTexture = 0
  48.   wallSideShader.textureTransformList[1].scale = vector(1, 0.5, 1)
  49.   theTex = gWorld.newTexture("WallTopTexture", #fromCastMember, member("tracktop", "Graphics"))
  50.   wallTopShader = gWorld.newShader("WallTopTexture", #standard)
  51.   wallTopShader.texture = theTex
  52.   wallTopShader.ambient = rgb(200, 200, 200)
  53.   wallTopShader.diffuse = rgb(255, 255, 255)
  54.   wallTopShader.specular = rgb(0, 0, 0)
  55.   wallTopShader.shininess = 0
  56.   wallTopShader.useDiffuseWithTexture = 0
  57.   wallTopShader.textureTransformList[1].scale = vector(1, 0.5, 1)
  58.   theTex = gWorld.newTexture("FinishLineTexture", #fromCastMember, member("Trackfinish", "Graphics"))
  59.   finishShader = gWorld.newShader("FinishLineShader", #standard)
  60.   finishShader.texture = theTex
  61.   finishShader.ambient = rgb(200, 200, 200)
  62.   finishShader.diffuse = rgb(255, 255, 255)
  63.   finishShader.specular = rgb(0, 0, 0)
  64.   finishShader.shininess = 0
  65.   finishShader.useDiffuseWithTexture = 0
  66.   finishShader.textureTransformList[1].scale = vector(1, 1, 1)
  67.   theTex = gWorld.newTexture("EndTexture", #fromCastMember, member("EndTexture"))
  68.   theTex.renderFormat = gSolidFormat
  69.   logoList = []
  70.   billboardList = []
  71.   theNamesList = ["bags", "getthetaste", "3dsfuncom", "swirlblue", "swirlorange"]
  72.   repeat with texName in theNamesList
  73.     theTex = gWorld.newTexture(texName & "Banner", #fromCastMember, member(texName))
  74.     theTex.renderFormat = gSolidFormat
  75.     theShader1 = gWorld.newShader(texName & "Shader", #standard)
  76.     theShader1.texture = theTex
  77.     theShader1.ambient = rgb(255, 255, 255)
  78.     theShader1.diffuse = rgb(255, 255, 255)
  79.     theShader1.emissive = rgb(255, 255, 255)
  80.     theShader1.shininess = 0
  81.     theShader1.textureTransformList[1].scale = vector(0.25, 1, 0.5)
  82.     theShader = gWorld.newShader(texName & "BillboardShader", #standard)
  83.     theShader.texture = theTex
  84.     theShader.ambient = rgb(255, 255, 255)
  85.     theShader.diffuse = rgb(255, 255, 255)
  86.     theShader1.emissive = rgb(255, 255, 255)
  87.     theShader.shininess = 0
  88.     theShader.textureTransformList[1].scale = vector(1, 1, 1)
  89.     if (texName = "bags") or (texName = "getthetaste") or (texName = "3dsfuncom") then
  90.       add(logoList, theShader1)
  91.       add(logoList, theShader1)
  92.       add(logoList, theShader1)
  93.       add(logoList, theShader1)
  94.       add(billboardList, theShader)
  95.     end if
  96.   end repeat
  97.   put billboardList
  98.   startShader = gWorld.newShader("StartShader", #standard)
  99.   startShader.texture = gWorld.texture("bagsBanner")
  100.   startShader.ambient = rgb(255, 255, 255)
  101.   startShader.diffuse = rgb(255, 255, 255)
  102.   startShader.shininess = 0
  103.   startShader.textureTransformList[1].scale = vector(1, 1, 1)
  104.   theTex = gWorld.newTexture("speedBoost", #fromCastMember, member("speedboost"))
  105.   theTex.renderFormat = gTransFormat
  106.   powerupShader = gWorld.newShader("SpeedBoostShader", #standard)
  107.   powerupShader.texture = theTex
  108.   powerupShader.ambient = rgb(255, 255, 255)
  109.   powerupShader.diffuse = rgb(255, 255, 255)
  110.   powerupShader.useDiffuseWithTexture = 0
  111.   powerupShader.shininess = 0
  112.   buildingModel = gWorld.cloneModelFromCastmember("Building1", "Building01", member("Building01"))
  113.   buildingModel.shader.textureTransformList[1].scale = vector(0.40000000000000002, 0.10000000000000001, 1)
  114.   buildingModel.shader.texture = gWorld.texture("BuildingTex_2")
  115.   buildingModel.removeFromWorld()
  116.   buildingResource = buildingModel.resource
  117.   buildingModel2 = buildingModel.clone("Building2")
  118.   buildingModel2.shader = gWorld.newShader("BuildingShader2", #standard)
  119.   buildingModel2.shader.texture = gWorld.texture("BuildingTex_1")
  120.   buildingModel2.shader.textureTransformList[1].scale = vector(0.40000000000000002, 0.10000000000000001, 1)
  121.   buildingModel2.shader.shininess = 0
  122.   buildingModel2.shader.ambient = buildingModel.shader.ambient
  123.   buildingModel2.shader.diffuse = buildingModel.shader.diffuse
  124.   trackGroup = gWorld.newGroup("TrackGroup")
  125.   havokTrackGroup = gWorld.newGroup("HavokTrackGroup")
  126.   buildingGroup = gWorld.newGroup("BuildingGroup")
  127.   vertList = []
  128.   havokVertList = []
  129.   gTargetPoints = []
  130.   currDirection = 0
  131.   currCenter = vector(0, 0, 0)
  132.   add(gTargetPoints, currCenter)
  133.   totalPieces = 0
  134.   radDirection = currDirection / 180.0 * PI
  135.   trackWidth = 50
  136.   wallHeight = 8
  137.   havokWallHeight = 20
  138.   wallWidth = 4
  139.   vertList = []
  140.   havokVertList = []
  141.   objectVertList = []
  142.   add(vertList, vector(-cos(radDirection) * (wallWidth + trackWidth), 0, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  143.   add(vertList, vector(-cos(radDirection) * (wallWidth + trackWidth), wallHeight, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  144.   add(vertList, vector(-cos(radDirection) * (trackWidth + 2), wallHeight, -sin(radDirection) * (trackWidth + 2)) + currCenter)
  145.   add(vertList, vector(-cos(radDirection) * trackWidth, 0, -sin(radDirection) * trackWidth) + currCenter)
  146.   add(vertList, vector(cos(radDirection) * trackWidth, 0, sin(radDirection) * trackWidth) + currCenter)
  147.   add(vertList, vector(cos(radDirection) * (trackWidth + 2), wallHeight, sin(radDirection) * (trackWidth + 2)) + currCenter)
  148.   add(vertList, vector(cos(radDirection) * (wallWidth + trackWidth), wallHeight, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  149.   add(vertList, vector(cos(radDirection) * (wallWidth + trackWidth), 0, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  150.   add(havokVertList, vector(-cos(radDirection) * (trackWidth + 4), havokWallHeight, -sin(radDirection) * (trackWidth + 4)) + currCenter)
  151.   add(havokVertList, vector(-cos(radDirection) * (trackWidth + 4), 0, -sin(radDirection) * (trackWidth + 4)) + currCenter)
  152.   add(havokVertList, vector(cos(radDirection) * (trackWidth + 4), 0, sin(radDirection) * (trackWidth + 4)) + currCenter)
  153.   add(havokVertList, vector(cos(radDirection) * (trackWidth + 4), havokWallHeight, sin(radDirection) * (trackWidth + 4)) + currCenter)
  154.   beginningVerts = vertList.duplicate()
  155.   beginningHavokVerts = havokVertList.duplicate()
  156.   repeat with i = 1 to theTrack.road.count
  157.     theType = theTrack.road[i].type
  158.     if i = 3 then
  159.       add(logoList, gWorld.shader("swirlbluebillboardShader"))
  160.       add(logoList, gWorld.shader("swirlorangebillboardShader"))
  161.     end if
  162.     repeat with k = vertList.count - VerticesPerSeg down to 1
  163.       deleteAt(vertList, k)
  164.     end repeat
  165.     repeat with k = havokVertList.count - havokVerticesPerSeg down to 1
  166.       deleteAt(havokVertList, k)
  167.     end repeat
  168.     trackObjects = []
  169.     objectVertList = []
  170.     numFaces = FacesPerSeg * theTrack.road[i].num
  171.     numVertices = VerticesPerSeg * (theTrack.road[i].num + 1)
  172.     numNormals = 0
  173.     numColors = 2
  174.     havokNumFaces = havokFacesPerSeg * theTrack.road[i].num
  175.     havokNumVertices = havokVerticesPerSeg * (theTrack.road[i].num + 1)
  176.     havokNumNormals = 0
  177.     havokNumColors = 2
  178.     havokNumTexCoords = 0
  179.     if (theType = #right) or (theType = #left) then
  180.       numTexCoords = 7
  181.       if theTrack.road[i].Degree > 40 then
  182.         theTrack.road[i].num = theTrack.road[i].num * 2
  183.         theTrack.road[i].Degree = theTrack.road[i].num / 2.0
  184.         isDoubled = 1
  185.         texCoordList = [[0.0, 0.0], [1, 0.0], [0.0, 1], [1, 1], [0.25, 0.0], [0.0, 1], [0.25, 1]]
  186.       else
  187.         isDoubled = 0
  188.         texCoordList = [[0.0, 0.0], [1, 0.0], [0.0, 1], [1, 1], [0.5, 0.0], [0.0, 1], [0.5, 1]]
  189.       end if
  190.     else
  191.       numTexCoords = 4
  192.       texCoordList = [[0.0, 0.0], [1, 0.0], [0.0, 1], [1, 1]]
  193.     end if
  194.     nm = gWorld.newMesh("trackMesh_" & i, numFaces, numVertices, numNormals, numColors, numTexCoords)
  195.     nm.colorList = [rgb("#FFFFFF"), rgb("#CCCC00")]
  196.     nm.textureCoordinateList = texCoordList
  197.     hnm = gWorld.newMesh("havokTrackMesh_" & i, havokNumFaces, havokNumVertices, havokNumNormals, havokNumColors, havokNumTexCoords)
  198.     faceCount = 0
  199.     havokFaceCount = 0
  200.     repeat with j = 1 to theTrack.road[i].num
  201.       if theTrack.objects.count < (totalPieces + 1) then
  202.         theTrack.objects[totalPieces + 1] = 0
  203.       end if
  204.       if theType = #right then
  205.         currDirection = currDirection + theTrack.road[i].Degree
  206.         leftOffset = theTrack.road[i].Degree * 2
  207.         rightOffset = -leftOffset
  208.         isTurn = 1
  209.       else
  210.         if theType = #left then
  211.           currDirection = currDirection - theTrack.road[i].Degree
  212.           rightOffset = theTrack.road[i].Degree * 2
  213.           leftOffset = -rightOffset
  214.           isTurn = 1
  215.         else
  216.           rightOffset = 0
  217.           leftOffset = 0
  218.           isTurn = 0
  219.         end if
  220.       end if
  221.       rightOffset = 0
  222.       leftOffset = 0
  223.       radDirection = currDirection / 180.0 * PI
  224.       if isTurn = 1 then
  225.         if isDoubled then
  226.           theDist = DistPerSection / 4
  227.         else
  228.           theDist = DistPerSection / 2
  229.         end if
  230.       else
  231.         theDist = DistPerSection
  232.       end if
  233.       if theType = #Connect then
  234.         repeat with l = 1 to beginningVerts.count
  235.           add(vertList, beginningVerts[l])
  236.         end repeat
  237.         repeat with l = 1 to beginningHavokVerts.count
  238.           add(havokVertList, beginningHavokVerts[l])
  239.         end repeat
  240.       else
  241.         newX = currCenter.x + (sin(radDirection) * theDist)
  242.         newY = currCenter.y + theTrack.road[i].height
  243.         newZ = currCenter.z - (cos(radDirection) * theDist)
  244.         if (j = theTrack.road[i].num) and (i < theTrack.road.count) then
  245.           oldHeight = newY - theTrack.road[i].height
  246.           nextHeight = newY + (theTrack.road[i + 1].height / 2)
  247.           newY = oldHeight + ((nextHeight - oldHeight) / 2)
  248.         else
  249.           if (j = 1) and (i > 1) and (i < theTrack.road.count) then
  250.             newY = newY - (theTrack.road[i].height / 2)
  251.           end if
  252.         end if
  253.         currCenter = vector(newX, newY, newZ)
  254.         add(gTargetPoints, currCenter)
  255.         add(vertList, vector(-cos(radDirection) * (wallWidth + trackWidth), 0 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  256.         add(vertList, vector(-cos(radDirection) * (wallWidth + trackWidth), wallHeight + leftOffset, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  257.         add(vertList, vector(-cos(radDirection) * (trackWidth + 2), wallHeight + leftOffset, -sin(radDirection) * (trackWidth + 2)) + currCenter)
  258.         add(vertList, vector(-cos(radDirection) * trackWidth, 0 + leftOffset, -sin(radDirection) * trackWidth) + currCenter)
  259.         add(vertList, vector(cos(radDirection) * trackWidth, 0 + rightOffset, sin(radDirection) * trackWidth) + currCenter)
  260.         add(vertList, vector(cos(radDirection) * (trackWidth + 2), wallHeight + rightOffset, sin(radDirection) * (trackWidth + 2)) + currCenter)
  261.         add(vertList, vector(cos(radDirection) * (wallWidth + trackWidth), wallHeight + rightOffset, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  262.         add(vertList, vector(cos(radDirection) * (wallWidth + trackWidth), 0 + rightOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  263.         add(havokVertList, vector(-cos(radDirection) * trackWidth, havokWallHeight + leftOffset, -sin(radDirection) * trackWidth) + currCenter)
  264.         add(havokVertList, vector(-cos(radDirection) * trackWidth, 0 + leftOffset, -sin(radDirection) * trackWidth) + currCenter)
  265.         add(havokVertList, vector(cos(radDirection) * trackWidth, 0 + rightOffset, sin(radDirection) * trackWidth) + currCenter)
  266.         add(havokVertList, vector(cos(radDirection) * trackWidth, havokWallHeight + rightOffset, sin(radDirection) * trackWidth) + currCenter)
  267.       end if
  268.       if theTrack.objects[totalPieces + 1] = #Billboard then
  269.         numTexCoords = 4
  270.         numFaces = 6
  271.         numNormals = 0
  272.         numColors = 3
  273.         numTexCoords = 4
  274.         texCoordList = [[0.0, 0.0], [1, 0.0], [0.0, 1], [1, 1]]
  275.         objectVertList = []
  276.         objFaceCount = 0
  277.         obj = gWorld.newMesh("objectMesh_" & i & "_" & j, numFaces, numVertices, numNormals, numColors, numTexCoords)
  278.         obj.colorList = [rgb("#FFFFFF"), rgb("#FFFFFF")]
  279.         obj.textureCoordinateList = texCoordList
  280.         add(objectVertList, vector(-cos(radDirection) * (wallWidth + trackWidth + 1), 0 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  281.         add(objectVertList, vector(-cos(radDirection) * (wallWidth + trackWidth + 1), 16 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  282.         add(objectVertList, vector(-cos(radDirection) * (wallWidth + trackWidth + 1), 30 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  283.         add(objectVertList, vector(-cos(radDirection) * (wallWidth + trackWidth), 0 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  284.         add(objectVertList, vector(-cos(radDirection) * (wallWidth + trackWidth), 16 + leftOffset - 0.05, -sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  285.         add(objectVertList, vector(cos(radDirection) * (wallWidth + trackWidth + 1), 0 + leftOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  286.         add(objectVertList, vector(cos(radDirection) * (wallWidth + trackWidth + 1), 16 + leftOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  287.         add(objectVertList, vector(cos(radDirection) * (wallWidth + trackWidth + 1), 30 + leftOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth + 0.20000000000000001)) + currCenter)
  288.         add(objectVertList, vector(cos(radDirection) * (wallWidth + trackWidth), 0 + leftOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  289.         add(objectVertList, vector(cos(radDirection) * (wallWidth + trackWidth), 16 + leftOffset - 0.05, sin(radDirection) * (wallWidth + trackWidth)) + currCenter)
  290.         objFaceCount = objFaceCount + 1
  291.         currNum = (trackObjects.count * 10) + 1
  292.         obj.face[objFaceCount].vertices = [currNum, currNum + 3, currNum + 1]
  293.         obj.face[objFaceCount].colors = [2, 2, 2]
  294.         objFaceCount = objFaceCount + 1
  295.         obj.face[objFaceCount].vertices = [currNum + 3, currNum + 4, currNum + 1]
  296.         obj.face[faceCount].colors = [2, 2, 2]
  297.         objFaceCount = objFaceCount + 1
  298.         obj.face[objFaceCount].vertices = [currNum + 8, currNum + 5, currNum + 9]
  299.         obj.face[objFaceCount].colors = [2, 2, 2]
  300.         objFaceCount = objFaceCount + 1
  301.         obj.face[objFaceCount].vertices = [currNum + 5, currNum + 6, currNum + 9]
  302.         obj.face[faceCount].colors = [2, 2, 2]
  303.         objFaceCount = objFaceCount + 1
  304.         theShader = billboardList[random(billboardList.count)]
  305.         obj.face[objFaceCount].vertices = [currNum + 2, currNum + 1, currNum + 6]
  306.         obj.face[objFaceCount].texCoords = [3, 1, 2]
  307.         obj.face[objFaceCount].shader = theShader
  308.         objFaceCount = objFaceCount + 1
  309.         obj.face[objFaceCount].vertices = [currNum + 2, currNum + 6, currNum + 7]
  310.         obj.face[objFaceCount].texCoords = [3, 2, 4]
  311.         obj.face[objFaceCount].shader = theShader
  312.         objFaceCount = objFaceCount + 1
  313.         obj.vertexList = objectVertList
  314.         obj.generateNormals(#flat)
  315.         obj.build()
  316.         obj = gWorld.newModel("Object_" & i & "_" & j, obj)
  317.         obj.parent = buildingGroup
  318.       end if
  319.       if theTrack.objects[totalPieces + 1] = #start then
  320.         numTexCoords = 4
  321.         numFaces = 6
  322.         numNormals = 0
  323.         numColors = 3
  324.         numTexCoords = 4
  325.         texCoordList = [[0.0, 0.0], [1, 0.0], [0.0, 1], [1, 1]]
  326.         objectVertList = []
  327.         objFaceCount = 0
  328.         obj = gWorld.newMesh("objectMesh_" & i & "_" & j, numFaces, numVertices, numNormals, numColors, numTexCoords)
  329.         obj.colorList = [rgb("#FFFFFF"), rgb("#FFFFFF")]
  330.         obj.textureCoordinateList = texCoordList
  331.         add(objectVertList, vector(-(wallWidth + trackWidth + 1), 0 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  332.         add(objectVertList, vector(-(wallWidth + trackWidth + 1), 16 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  333.         add(objectVertList, vector(-(wallWidth + trackWidth + 1), 30 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  334.         add(objectVertList, vector(-(wallWidth + trackWidth), 0 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  335.         add(objectVertList, vector(-(wallWidth + trackWidth), 16 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  336.         add(objectVertList, vector(wallWidth + trackWidth + 1, 0 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  337.         add(objectVertList, vector(wallWidth + trackWidth + 1, 16 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  338.         add(objectVertList, vector(wallWidth + trackWidth + 1, 30 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  339.         add(objectVertList, vector(wallWidth + trackWidth, 0 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  340.         add(objectVertList, vector(wallWidth + trackWidth, 16 + leftOffset - 0.05, 0) + vector(0, 0, -155))
  341.         objFaceCount = objFaceCount + 1
  342.         currNum = (trackObjects.count * 10) + 1
  343.         obj.face[objFaceCount].vertices = [currNum, currNum + 3, currNum + 1]
  344.         obj.face[objFaceCount].colors = [2, 2, 2]
  345.         objFaceCount = objFaceCount + 1
  346.         obj.face[objFaceCount].vertices = [currNum + 3, currNum + 4, currNum + 1]
  347.         obj.face[faceCount].colors = [2, 2, 2]
  348.         objFaceCount = objFaceCount + 1
  349.         obj.face[objFaceCount].vertices = [currNum + 8, currNum + 5, currNum + 9]
  350.         obj.face[objFaceCount].colors = [2, 2, 2]
  351.         objFaceCount = objFaceCount + 1
  352.         obj.face[objFaceCount].vertices = [currNum + 5, currNum + 6, currNum + 9]
  353.         obj.face[faceCount].colors = [2, 2, 2]
  354.         objFaceCount = objFaceCount + 1
  355.         theShader = startShader
  356.         obj.face[objFaceCount].vertices = [currNum + 2, currNum + 1, currNum + 6]
  357.         obj.face[objFaceCount].texCoords = [3, 1, 2]
  358.         obj.face[objFaceCount].shader = theShader
  359.         objFaceCount = objFaceCount + 1
  360.         obj.face[objFaceCount].vertices = [currNum + 2, currNum + 6, currNum + 7]
  361.         obj.face[objFaceCount].texCoords = [3, 2, 4]
  362.         obj.face[objFaceCount].shader = theShader
  363.         objFaceCount = objFaceCount + 1
  364.         obj.vertexList = objectVertList
  365.         obj.generateNormals(#flat)
  366.         obj.build()
  367.         obj = gWorld.newModel("Object_" & i & "_" & j, obj)
  368.         obj.parent = buildingGroup
  369.       end if
  370.       if theTrack.objects[totalPieces + 1] = #Building then
  371.         if random(2) = 1 then
  372.           tempBuilding = buildingModel.clone("Building_" & totalPieces)
  373.         else
  374.           tempBuilding = buildingModel2.clone("Building_" & totalPieces)
  375.         end if
  376.         leftRightAmount = random(50) + 250
  377.         if random(2) = 1 then
  378.           tempBuilding.transform.position = vector(-cos(radDirection) * leftRightAmount, -960, -sin(radDirection) * leftRightAmount) + currCenter
  379.         else
  380.           tempBuilding.transform.position = vector(cos(radDirection) * leftRightAmount, -960, sin(radDirection) * leftRightAmount) + currCenter
  381.         end if
  382.         tempBuilding.transform.scale = vector(random(30) + 5, random(30) + 5, random(20) + 50)
  383.         tempBuilding.transform.rotation = vector(-90, random(-45, 45), 0)
  384.         tempBuilding.parent = buildingGroup
  385.       end if
  386.       if theTrack.objects[totalPieces + 1] = #Powerup then
  387.         if voidp(gWorld.modelResource("PowerupObject")) then
  388.           tp = gWorld.newModelResource("PowerupObject", #plane)
  389.           tp.length = 6
  390.           tp.width = 20
  391.         else
  392.           tp = gWorld.modelResource("PowerupObject")
  393.         end if
  394.         Powerup = gWorld.newModel("Powerup_" & i & "_" & j, tp)
  395.         leftRightOffset = random(-20, 20)
  396.         Powerup.transform.position = vector(-cos(radDirection) * leftRightOffset, 6, -sin(radDirection) * leftRightOffset) + currCenter
  397.         Powerup.shaderList = powerupShader
  398.         if voidp(gWorld.modelResource("PowerupSparksResource")) then
  399.           ts = gWorld.newModelResource("PowerupSparksResource", #particle)
  400.           ts.sizeRange.start = 0.29999999999999999
  401.           ts.sizeRange.end = 0.80000000000000004
  402.           ts.lifeTime = 3000
  403.           ts.emitter.minSpeed = 8
  404.           ts.emitter.maxSpeed = 15
  405.           ts.colorRange.end = rgb("FF9900")
  406.           ts.colorRange.start = rgb("FFFF00")
  407.           ts.emitter.numParticles = 200
  408.           ts.emitter.mode = #stream
  409.           ts.emitter.loop = 1
  410.           ts.emitter.angle = 30
  411.           ts.emitter.direction = vector(0, 1, 0)
  412.           ts.emitter.path = [vector(0, 0, 0), vector(0, 30, 0)]
  413.           ts.emitter.pathStrength = 0.001
  414.         else
  415.           ts = gWorld.modelResource("PowerupSparksResource")
  416.         end if
  417.         tm = gWorld.newModel("PowerupSparks_" & i & "_" & j, ts)
  418.         tm.parent = Powerup
  419.         tm.transform.position = vector(0, -8, 0)
  420.         add(gPowerupList, Powerup)
  421.       end if
  422.       baseNum = ((j - 1) * VerticesPerSeg) + 1
  423.       colorReverse = 0
  424.       currRoadShader = (currRoadShader mod 2) + 1
  425.       faceCount = faceCount + 1
  426.       nm.face[faceCount].vertices = [baseNum, baseNum + 1, baseNum + 8]
  427.       nm.face[faceCount].texCoords = [3, 4, 1]
  428.       nm.face[faceCount].shader = wallSideShader
  429.       faceCount = faceCount + 1
  430.       nm.face[faceCount].vertices = [baseNum + 1, baseNum + 9, baseNum + 8]
  431.       nm.face[faceCount].texCoords = [4, 2, 1]
  432.       nm.face[faceCount].shader = wallSideShader
  433.       faceCount = faceCount + 1
  434.       nm.face[faceCount].vertices = [baseNum + 1, baseNum + 2, baseNum + 9]
  435.       nm.face[faceCount].texCoords = [4, 3, 2]
  436.       nm.face[faceCount].shader = wallTopShader
  437.       faceCount = faceCount + 1
  438.       nm.face[faceCount].vertices = [baseNum + 2, baseNum + 10, baseNum + 9]
  439.       nm.face[faceCount].texCoords = [3, 1, 2]
  440.       nm.face[faceCount].shader = wallTopShader
  441.       faceCount = faceCount + 1
  442.       shader1 = logoList[random(logoList.count)]
  443.       shader2 = logoList[random(logoList.count)]
  444.       nm.face[faceCount].vertices = [baseNum + 2, baseNum + 3, baseNum + 11]
  445.       if colorReverse then
  446.         if isTurn then
  447.           nm.face[faceCount].texCoords = [6, 1, 5]
  448.         else
  449.           nm.face[faceCount].texCoords = [3, 1, 2]
  450.         end if
  451.         nm.face[faceCount].shader = shader1
  452.       else
  453.         if isTurn then
  454.           nm.face[faceCount].texCoords = [6, 1, 5]
  455.         else
  456.           nm.face[faceCount].texCoords = [3, 1, 2]
  457.         end if
  458.         nm.face[faceCount].shader = shader1
  459.       end if
  460.       faceCount = faceCount + 1
  461.       nm.face[faceCount].vertices = [baseNum + 2, baseNum + 11, baseNum + 10]
  462.       if colorReverse then
  463.         if isTurn then
  464.           nm.face[faceCount].texCoords = [6, 5, 7]
  465.         else
  466.           nm.face[faceCount].texCoords = [3, 2, 4]
  467.         end if
  468.         nm.face[faceCount].shader = shader1
  469.       else
  470.         if isTurn then
  471.           nm.face[faceCount].texCoords = [6, 5, 7]
  472.         else
  473.           nm.face[faceCount].texCoords = [3, 2, 4]
  474.         end if
  475.         nm.face[faceCount].shader = shader1
  476.       end if
  477.       faceCount = faceCount + 1
  478.       nm.face[faceCount].vertices = [baseNum + 3, baseNum + 4, baseNum + 12]
  479.       if colorReverse then
  480.         nm.face[faceCount].texCoords = [1, 2, 4]
  481.         if totalPieces = 0 then
  482.           nm.face[faceCount].shader = finishShader
  483.         else
  484.           nm.face[faceCount].shader = roadShaders[currRoadShader]
  485.         end if
  486.       else
  487.         nm.face[faceCount].texCoords = [1, 2, 4]
  488.         if totalPieces = 0 then
  489.           nm.face[faceCount].shader = finishShader
  490.         else
  491.           nm.face[faceCount].shader = roadShaders[currRoadShader]
  492.         end if
  493.       end if
  494.       faceCount = faceCount + 1
  495.       nm.face[faceCount].vertices = [baseNum + 3, baseNum + 12, baseNum + 11]
  496.       if colorReverse then
  497.         nm.face[faceCount].texCoords = [1, 4, 3]
  498.         if totalPieces = 0 then
  499.           nm.face[faceCount].shader = finishShader
  500.         else
  501.           nm.face[faceCount].shader = roadShaders[currRoadShader]
  502.         end if
  503.       else
  504.         nm.face[faceCount].texCoords = [1, 4, 3]
  505.         if totalPieces = 0 then
  506.           nm.face[faceCount].shader = finishShader
  507.         else
  508.           nm.face[faceCount].shader = roadShaders[currRoadShader]
  509.         end if
  510.       end if
  511.       faceCount = faceCount + 1
  512.       nm.face[faceCount].vertices = [baseNum + 4, baseNum + 5, baseNum + 13]
  513.       if colorReverse then
  514.         if isTurn then
  515.           nm.face[faceCount].texCoords = [5, 7, 6]
  516.         else
  517.           nm.face[faceCount].texCoords = [2, 4, 3]
  518.         end if
  519.         nm.face[faceCount].shader = shader2
  520.       else
  521.         if isTurn then
  522.           nm.face[faceCount].texCoords = [5, 7, 6]
  523.         else
  524.           nm.face[faceCount].texCoords = [2, 4, 3]
  525.         end if
  526.         nm.face[faceCount].shader = shader2
  527.       end if
  528.       faceCount = faceCount + 1
  529.       nm.face[faceCount].vertices = [baseNum + 4, baseNum + 13, baseNum + 12]
  530.       if colorReverse then
  531.         if isTurn then
  532.           nm.face[faceCount].texCoords = [5, 6, 1]
  533.         else
  534.           nm.face[faceCount].texCoords = [2, 3, 1]
  535.         end if
  536.         nm.face[faceCount].shader = shader2
  537.       else
  538.         if isTurn then
  539.           nm.face[faceCount].texCoords = [5, 6, 1]
  540.         else
  541.           nm.face[faceCount].texCoords = [2, 3, 1]
  542.         end if
  543.         nm.face[faceCount].shader = shader2
  544.       end if
  545.       faceCount = faceCount + 1
  546.       nm.face[faceCount].vertices = [baseNum + 5, baseNum + 6, baseNum + 14]
  547.       nm.face[faceCount].texCoords = [3, 2, 4]
  548.       nm.face[faceCount].shader = wallTopShader
  549.       faceCount = faceCount + 1
  550.       nm.face[faceCount].vertices = [baseNum + 5, baseNum + 14, baseNum + 13]
  551.       nm.face[faceCount].texCoords = [3, 4, 1]
  552.       nm.face[faceCount].shader = wallTopShader
  553.       faceCount = faceCount + 1
  554.       nm.face[faceCount].vertices = [baseNum + 6, baseNum + 7, baseNum + 15]
  555.       nm.face[faceCount].texCoords = [4, 3, 1]
  556.       nm.face[faceCount].shader = wallSideShader
  557.       faceCount = faceCount + 1
  558.       nm.face[faceCount].vertices = [baseNum + 6, baseNum + 15, baseNum + 14]
  559.       nm.face[faceCount].texCoords = [4, 1, 2]
  560.       nm.face[faceCount].shader = wallSideShader
  561.       faceCount = faceCount + 1
  562.       nm.face[faceCount].vertices = [baseNum + 0, baseNum + 8, baseNum + 7]
  563.       nm.face[faceCount].texCoords = [3, 1, 4]
  564.       nm.face[faceCount].shader = roadBotShader
  565.       faceCount = faceCount + 1
  566.       nm.face[faceCount].vertices = [baseNum + 7, baseNum + 8, baseNum + 15]
  567.       nm.face[faceCount].texCoords = [4, 1, 2]
  568.       nm.face[faceCount].shader = roadBotShader
  569.       baseNum = ((j - 1) * havokVerticesPerSeg) + 1
  570.       havokFaceCount = havokFaceCount + 1
  571.       hnm.face[havokFaceCount].vertices = [baseNum, baseNum + 1, baseNum + 4]
  572.       havokFaceCount = havokFaceCount + 1
  573.       hnm.face[havokFaceCount].vertices = [baseNum + 1, baseNum + 5, baseNum + 4]
  574.       havokFaceCount = havokFaceCount + 1
  575.       hnm.face[havokFaceCount].vertices = [baseNum + 1, baseNum + 2, baseNum + 5]
  576.       havokFaceCount = havokFaceCount + 1
  577.       hnm.face[havokFaceCount].vertices = [baseNum + 2, baseNum + 6, baseNum + 5]
  578.       havokFaceCount = havokFaceCount + 1
  579.       hnm.face[havokFaceCount].vertices = [baseNum + 2, baseNum + 3, baseNum + 6]
  580.       havokFaceCount = havokFaceCount + 1
  581.       hnm.face[havokFaceCount].vertices = [baseNum + 3, baseNum + 7, baseNum + 6]
  582.       totalPieces = totalPieces + 1
  583.     end repeat
  584.     nm.vertexList = vertList
  585.     nm.generateNormals(#flat)
  586.     nm.build()
  587.     hnm.vertexList = havokVertList
  588.     hnm.build()
  589.     nm = gWorld.newModel("Track_" & i, nm)
  590.     nm.parent = trackGroup
  591.     hnm = gWorld.newModel("HavokTrack_" & i, hnm)
  592.     hnm.parent = havokTrackGroup
  593.     nm.transform.position = vector(0, -7, 0)
  594.     hnm.transform.position = vector(0, -8, 0)
  595.   end repeat
  596.   the randomSeed = the milliSeconds
  597.   return 
  598. end
  599.